package mcu.market.net.model;

import java.util.List;

import javax.swing.JLabel;
import javax.swing.JTextArea;

import mcu.market.ibatis.IBatisFactory;
import mcu.market.ibatis.bean.BeanCompany;

import org.apache.ibatis.session.SqlSession;

public abstract class getSwtDataModel implements getDataFromWeb{
	String actName=null;
	JLabel jb=null;
	JTextArea jta=null;
	private long time1, time2;
	
	public JLabel getJb() {
		return jb;
	}
	public void setJb(JLabel jb) {
		this.jb = jb;
	}
	public JTextArea getJta() {
		return jta;
	}
	public void setJta(JTextArea jta) {
		this.jta = jta;
	}
	/**
	 * 設定行為名稱
	 * @param actName
	 */
	public void setActName(String actName) {
		this.actName = actName;
	}
	/**
	 * 開始程式
	 */
	public void programStart() {
		this.time1 = System.currentTimeMillis();    
	}
	/**
	 * 程式結束
	 */
	public void programEnd() {   
		this.time2 = System.currentTimeMillis();
        System.out.println("花了：" + (this.time2-this.time1)/1000 + "秒");
	}
	/**
	 * 印
	 * @param str
	 */
	public void print(String str) {
		print(str,true);
	}
	/**
	 * 
	 * @param str
	 * @param input_print 是否在CONSOLE顯示
	 */
	public void print(String str,boolean input_print) {
		if(input_print)System.out.println(str);
		if(this.jb!=null){
			jb.setText(str);
		}else if(this.jta!=null){
			jta.append("\n"+str);
		}
	}
	/**
	 * 取行為名稱
	 * @return
	 */
	public String getActName() {
		return actName;
	}
	/**
	 * 
	 * @param Type 1=listed ,2=OTC
	 * @return
	 */
	private static List<BeanCompany> getCompany(int Type){
		SqlSession sqlSession=IBatisFactory.getInstance().getSqlSession();
		BeanCompany bean =new BeanCompany();
		bean.setType(Type);
		List<BeanCompany> list=sqlSession.selectList("company.selectTypeCompany",bean);
		sqlSession.close();
		return list;
	}
}
